//
//  PhoneViewController.m
//  IBaby
//
//  Created by ZengYuan on 14/11/19.
//  Copyright (c) 2014年 com.zhongwei. All rights reserved.
//

#import "PhoneViewController.h"
#import "VerifycodeViewController.h"
#include <pthread.h>


@interface PhoneViewController ()

@end

@implementation PhoneViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = BACKVIEWCOLOR;
    //    phoneField.delegate=self;
    
    //    [self addTwoLinesFor:coverView];
    [phoneField becomeFirstResponder];
    
    //    [self setBtnDisabledDarkBackgroundImage:nextBtn];
    
    
    [nextBtn setBackgroundImage:[UIImage resizableImage:@"圆角矩形-3"] forState:UIControlStateNormal];
    nextBtn.titleLabel.font = LONGBTN_FONT;
    coverView.layer.cornerRadius=5;
    
    if (self.phone_func != REG_ACCOUNT) {
        self.agree.hidden=YES;
        self.agreeUseBtn.userInteractionEnabled=NO;
    }
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.titleLabel.text=@"输入手机号";
    
    //    self.navigationItem.title=@"请输入手机号";
}

- (IBAction)next:(id)sender {
    if ([phoneField.text length] == 0) {
        MBALERT(@"手机号不能为空");
        return;
    }
    
    NSString* rule1 = @"^1(3|5|7|8|4)\\d{9}";
    NSPredicate* pred=[NSPredicate predicateWithFormat:@"SELF MATCHES %@",rule1];
    BOOL isMatch=[pred evaluateWithObject:phoneField.text];
    if(!isMatch){
        MBALERT(@"手机号格式不正确");
        return;
    }
    
    [self checkUserExisted];
}

-(void)checkUserExisted{
    
    UIStoryboard *board = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    VerifycodeViewController *regvc = [board instantiateViewControllerWithIdentifier:@"vcvc"];
    regvc.phone=phoneField.text;
    [self.navigationController pushViewController:regvc animated:YES];

}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
 
 if (range.location==0 && [string length]==0 ){
 [self setBtnDisabledDarkBackgroundImage:nextBtn];
 }else {
 [self setBtnGreenBackgroundImage:nextBtn];
 }
 
 return YES;
 }
 
 - (BOOL)textFieldShouldClear:(UITextField *)textField{
 [self setBtnDisabledDarkBackgroundImage:nextBtn];
 return YES;
 }
 
 */

-(void)navLeftAction{
    [self.navigationController trvs_popViewControllerWithNavigationControllerTransition];
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

- (IBAction)agreeUse:(id)sender {
    

    
}
@end
